//
//  EnterpriseViewController.m
//  OfferJob
//
//  Created by 河南动力无限科技有限公司 on 17/7/13.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "EnterpriseViewController.h"
#import "CellView.h"
@interface EnterpriseViewController ()<UITextFieldDelegate>
@property (nonatomic,strong)NSMutableDictionary* dic;
@end

@implementation EnterpriseViewController

- (void)viewDidLoad {
    self.title=@"企业信息";
    [super viewDidLoad];
    self.view .backgroundColor=backgroundcolor;
    _dic=[[NSMutableDictionary alloc]init];
 
    [self  getInfo];
    
}
- (void)getInfo{

    
    FXTHttpRequestModel * requestModel = [[FXTHttpRequestModel alloc] init];
    requestModel.type = FXTHttpType_GET;
    requestModel.appendUrl = @"/Seller/company";
    NSMutableDictionary * paramDic = [NSMutableDictionary dictionary];
    [paramDic setValue:tokenn forKey:@"token"];
    requestModel.paramDic = paramDic;
    requestModel.callback = ^(FXTHttpResponseModel * result, NSError *error){
        if (result.state ==FXTReponseCodeState_Success) {
            NSLog(@"请求的结果是%@",result.data);
            _dic=result.data;
     [self getUI];
        }else {
            [DisplayHelper displayWarningAlert:result.alertMsg];
        }
    };
    [[FXTHttpSessionManager sharedHttpSessionManager] sendHttpRequestParam:requestModel];
    

}
- (void)getUI{

    
    
    
    //    UIButton *  tempBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    //    [tempBtn setAdjustsImageWhenHighlighted:NO];
    //      tempBtn.frame = CGRectMake(0, 0, 80, 44);
    //    tempBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica Neue" size:16.0f];
    //    [tempBtn setTitle:@"编辑" forState:UIControlStateNormal];
    //    [tempBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    //    [tempBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //    [tempBtn addTarget:self action:@selector(registerUsers) forControlEvents:UIControlEventTouchUpInside];
    //    UIBarButtonItem *rightBarItem=[[UIBarButtonItem alloc] initWithCustomView:tempBtn];
    //    self.navigationItem.rightBarButtonItem = rightBarItem;
       float setY=10*kAppScale;
    NSArray *MArr=@[@"公司名称:",@"公司地址:"];
    NSArray *VArr=@[@"请输入公司名称",@"请输入公司地址 "];
    NSArray*tarr=@[[NSString stringWithFormat:@"%@",[_dic objectForKey:@"company_name"]],[NSString stringWithFormat:@"%@",[_dic objectForKey:@"company_address"]]];
    for (int i=0; i<[MArr count]; i++) {
        CellView *cell=[[CellView alloc]initWithFrame:CGRectMake(10*kAppScale, setY, self.view.width-20*kAppScale, 44*kAppScale)];
        cell.titleLabel.textColor=blackTextColor;
        cell.titleLabel.text=MArr[i];
        cell.titleLabel.textAlignment=NSTextAlignmentLeft;
        
        UITextField *textF=[[UITextField alloc]initWithFrame:CGRectMake(90*kAppScale, 7*kAppScale, 280*kAppScale, cell.height-10*kAppScale)];
        textF.font=[UIFont systemFontOfSize:13*kAppScale];
        textF.placeholder=VArr[i];
        textF.text=tarr[i];
        textF.delegate=self;
        textF.tag=10+i;
        [cell addSubview:textF];
        
        [self.view addSubview:cell];
        setY=cell.bottom;
    }
    
    setY+=10;

        NSArray*tarre=@[[NSString stringWithFormat:@"%@",[_dic objectForKey:@"contact"]],[NSString stringWithFormat:@"%@",[_dic objectForKey:@"email"]] ,[NSString stringWithFormat:@"%@",[_dic objectForKey:@"contact_phone"]]];
    NSArray *MAr=@[@"联系人:",@"联系电话:",@"企业邮箱"];
    NSArray *VAr=@[@"请输入联系人",@"请输入联系人",@"请输入企业邮箱"];
    for (int i=0; i<[MAr count]; i++) {
        CellView *cell=[[CellView alloc]initWithFrame:CGRectMake(10*kAppScale, setY, self.view.width-20*kAppScale, 44*kAppScale)];
        cell.titleLabel.textColor=blackTextColor;
        cell.titleLabel.text=MAr[i];
        cell.titleLabel.textAlignment=NSTextAlignmentLeft;
        
        UITextField *textF=[[UITextField alloc]initWithFrame:CGRectMake(90*kAppScale, 7*kAppScale, 280*kAppScale, cell.height-10*kAppScale)];
        textF.font=[UIFont systemFontOfSize:13*kAppScale];
        textF.placeholder=VAr[i];
        textF.delegate=self;
        textF.tag=100+i;
        textF.text=tarre[i];
        [cell addSubview:textF];
        
        [self.view addSubview:cell];
        setY=cell.bottom;
    }
    
    
    
    
    UIButton *nextBtn=[[UIButton alloc]initWithFrame:CGRectMake(10*kAppScale,setY+50*kAppScale,SCREEN_WIDTH-20*kAppScale,44*kAppScale)];
    nextBtn.backgroundColor=NavCOLOR;
    [nextBtn setTitle:@"保存" forState:UIControlStateNormal];
    [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    nextBtn.titleLabel.font=[UIFont systemFontOfSize:12*kAppScale];
    [nextBtn addTarget:self action:@selector(nextBtnEvent) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nextBtn];

}

- (void)nextBtnEvent{

    
    
    UITextField *nameField = (UITextField *)[self.view viewWithTag:10];
    NSString *nameStr = nameField.text ;
    
    
    UITextField *addressTextF = (UITextField *)[self.view viewWithTag:11];
    NSString *addressStr = addressTextF.text ;
    
    UITextField *manTextField = (UITextField *)[self.view viewWithTag:100];
    NSString *namStr = manTextField.text ;
    
    
    UITextField *telTextF = (UITextField *)[self.view viewWithTag:101];
    NSString *telStr = telTextF.text ;
    
    UITextField *emailTextF = (UITextField *)[self.view viewWithTag:102];
    NSString *emailStr = emailTextF.text ;
    
    
        FXTHttpRequestModel * requestModel = [[FXTHttpRequestModel alloc] init];
        requestModel.type = FXTHttpType_POST;
        requestModel.appendUrl = @"/Seller/company";
        NSMutableDictionary * paramDic = [NSMutableDictionary dictionary];
        [paramDic setValue:tokenn forKey:@"token"];
     [paramDic setValue:nameStr forKey:@"company_name"];
     [paramDic setValue:addressStr forKey:@"company_address"];
     [paramDic setValue:namStr forKey:@"contact"];
     [paramDic setValue:telStr forKey:@"contact_phone"];
     [paramDic setValue:emailStr forKey:@"email"];
//        [paramDic setValue:[_dic objectForKey:@"seller_id"] forKey:@"seller_id"];
        requestModel.paramDic = paramDic;
        requestModel.callback = ^(FXTHttpResponseModel * result, NSError *error){
            if (result.state ==FXTReponseCodeState_Success) {
                NSLog(@"请求的结果是%@",result.data);
                 [DisplayHelper displayWarningAlert:result.alertMsg];
                
            }else {
                [DisplayHelper displayWarningAlert:result.alertMsg];
            }
        };
        [[FXTHttpSessionManager sharedHttpSessionManager] sendHttpRequestParam:requestModel];
    
    
    
    

}

//- (void)registerUsers{
//
//
//
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
